// pages/orderSuccess/index.js
import {
  // serializeParams
  matchDictList
} from "../../utils/index.js";
import Toast from '@vant/weapp/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detailData: {},
    customerAddress: "",
    sellerAddress: "",
    lockInfoType: "",
    fileList: [],
    showDetail: false //是否为查看详情
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.showDetail) {
      this.setData({
        showDetail: true
      });
      getApp().globalData.hasAdd = false;
    } else {
      getApp().globalData.hasAdd = true; //已经添加
    }
    this.getDetail(options.orderId);
  },
  async getDetail(id) {
    // wx.showLoading({
    //   title: '正在加载',
    //   mask: true
    // })
    Toast.loading({
      message: '加载中...',
      forbidClick: true,
      mask: true
    })
    const {
      openid
    } = wx.getStorageSync('idInfo') ? wx.getStorageSync('idInfo') : null;
    getApp().globalData.wxCloudRequest({
      type: "getOrderDetail",
      id,
      openId: openid
    }).then(({
      result
    }) => {
      const lockInfoList = wx.getStorageSync('dicts') ? wx.getStorageSync('dicts')["lockType"] : [];
      this.setData({
        detailData: result.data,
        customerAddress: result.data.customerData.regionValue.join(""),
        sellerAddress: result.data.sellerData.regionValue.join(""),
        lockInfoType: matchDictList(result.data.lockInfo.type, lockInfoList, "dictValue", "dictLabel"),
        fileList: result.data.imgs
      });
      // wx.hideLoading();
      Toast.clear();
    }).catch((err) => {})
  },
  toOrderList() {

    wx.switchTab({
      url: '/pages/orderList/index',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})